$(document).ready(function() {
	var cookie = $.AMUI.utils.cookie;
	var sessionId = (cookie.get("sessionId") == null) ? "" : cookie.get("sessionId");

	$.getJSON("json/locat.json", function(data) {
		var locat = data["url"];
		var originalID = data["originalID"];
		/*if(null == sessionId || "undefined" == sessionId || "" == sessionId) {
			window.location.href = "login.html";
		} else {*/
			$.ajax(locat + '/appClient/toEditInfo', {
				dataType: 'json',
				type: 'POST',
				data: {
					'originalID': originalID
				},
				timeout: 10000,
				xhrFields: {
					withCredentials: true,
					useDefaultXhrHeader: false
				},
				crossDomain: true,
				success: function(data) {
					if("success" == data["msg"]) {
						jQuery("#select").empty();
						for(i = 0; i <= data["jsonDocFactories"].length - 1; i++) {
							document.getElementById("select").options.add(new Option(
								data["jsonDocFactories"][i]["factoryName"], data["jsonDocFactories"][i]["id"]));
						}
						for(i = 0; i <= data["oldfactorys"].length - 1; i++) {
							$("#select").find("option[value ='" + data["oldfactorys"][i]["id"] + "']").attr("selected", true);
						}
						document.getElementById("username").value = data["username"];
						document.getElementById("phone").value = data["phone"];
						document.getElementById("wx_id").value = data["wx_id"];
					} else if("login" == data["msg"]) {
						swal("登录超时，请重新登录。");
						window.location.href = "login.html";
					} else {
						swal("系统异常，用户未关注工厂。");
					}
				},
				error: function() {
					swal("服务或网络异常，稍后再试！", "", "error");
				}

			});
		//}

	})

})